package com.soft.mapper;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.soft.entity.Dept;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class DeptMapperTest {
	@Autowired
	private DeptMapper deptMapper;
	//@Test
	public void testSelect()
	{
		List<Dept> deptList = deptMapper.selectList(null);
		for(int i = 0;i < deptList.size();i++)
		{
			System.out.println(deptList.get(i).getDname());
		}
	}
	//@Test
	public void testinsert() {
	    Dept dept = new Dept();
	    dept.setDname("王朝");
	    dept.setLoc("开封");
	    deptMapper.insert(dept);
	}
	//@Test
	public void updateTest() {
	    Dept dept = new Dept();
	    dept.setDeptno("1");
	    dept.setDname("aaaa");
	    dept.setLoc("aaaa");
	    deptMapper.updateById(dept);
	}
	//@Test
	public void selectIdTest()
	{
		Dept dept = deptMapper.selectById(2);
		System.out.println(dept.getDname());
	}
	@Test
	public void selectOneTest() {
		QueryWrapper<Dept> qw = new QueryWrapper<>();
		qw.gt("deptno", 1);
		try
		{
			Dept dept = deptMapper.selectOne(qw);
			System.out.println(dept);
		}catch(Exception e)
		{
			System.out.println("用户名和密码重复，请修改密码");
		}

	}
	//@Test
	public void updateQueryTest()
	{
		UpdateWrapper<Dept> uw = new UpdateWrapper<>();
		uw.gt("deptno", 1);
		Dept dept = new Dept();
		dept.setLoc("雄安");
		deptMapper.update(dept,uw);
		int num = deptMapper.update(dept,uw);
		System.out.println(num);
	}
	//@Test
	public void deleteTest() {
	    Dept dept = new Dept();
	    dept.setDeptno("2");
	    deptMapper.deleteById(dept);
	}
	//@Test
	public void deleteQueryTest()
	{
		QueryWrapper<Dept> qw = new QueryWrapper();
		qw.eq("dept_name", "王朝");
		deptMapper.delete(qw);
	}
}
